<template>
	<div class="my_l">
		<header class="top_bar">
			<a onclick="window.history.go(-1)" class="icon_back"></a>
			<h3 class="cartname">商城登录</h3>
		</header>
		<main class="user_login_box">
			<div class="login_dialog">
				<div class="_username position_rel">
					<img class="login_accout_icon" src="../assets/images/account_icon.png"/>
					<input @change="changeVal" type="text" placeholder="请输入用户名" class="user_input" v-model="username" />
				</div>
				<div class="_username u_passwd position_rel">
					<img class="login_accout_icon" src="../assets/images/password_icon.png"/>
					<input type="password" placeholder="请输入密码" class="user_input" v-model="password" />
				</div>

				<div class="login_box">
					<a @click="goLogin()" class="btn_login">登录</a>
				</div>
				<div class="go_find_pwd_box">
					<router-link tag="span" to="/wx/findPassword">找回密码</router-link>
				</div>
				<div class="go_reg_box">
					<router-link tag="span" to="/wx/register">快速注册</router-link>
				</div>
			</div>
		</main>
	</div>
</template>
<script>
	import { Toast } from 'mint-ui';

	export default {
		created() {
//			let _this = this
//			console.log('location.search', location.search)
//			if(location.search === '') {
//				location.href = 'http://pstsc.pstech360.com/base/wechatLogin'
//			}
//			var urlParam = location.href
//			urlParam = urlParam.split('?')[1].split('=')[1]
//			if(urlParam === '') {
//				location.href = 'http://pstsc.pstech360.com/base/wechatLogin'
//			}
//			_this.openid = urlParam
//			console.log('urlParam', urlParam)
		},
		data() {
			return {
				username: '',
				password: '',
				userInfo: {},
				openid: '',
			}
		},
		methods: {
			goLogin() {
				let _this = this;
				if(_this.username == '') {
					Toast('请输入用户名');
				} else if(_this.password == '') {
					Toast('请输入密码');
				} else {
					_this.$http.post('/base/login', {
						CellPhone: _this.username,
						Password: _this.password,
						OpenId: _this.openid,
					}, undefined, res => {
						console.log('登录res', res)
						if(res.code === 200) {
							_this.$store.state.user_name = _this.username
							window.localStorage.Authorization = res.data;
							Toast('登录成功！');
							setTimeout(function() {
								if(localStorage.fromPath) {
									_this.$router.push({
										path: localStorage.fromPath
									});
								} else {
									_this.$router.push({
										path: '/wx/home'
									});
								}
							}, 1500)

						} else {
							Toast(res.error);
						}
					})
				}
			},
			changeVal() {
				this.$store.state.user_name = this.username
			},
		}
	}
</script>
<style>
	@import '../assets/css/login.css';
</style>
<style>
	.go_find_pwd_box {
		float: left;
	}
	
	.go_find_pwd_box span {
		display: inline-block;
		color: #aaa;
		height: 20px;
		line-height: 20px;
		margin-top: 10px;
	}
</style>